package pkg

import (
	"github.com/gin-gonic/gin"
	"shop/internal/controller/base"
	"shop/middleware"
)

func TokenMiddle() gin.HandlerFunc {
	return func(c *gin.Context) {
		authorization := c.GetHeader("Authorization")
		claims := middleware.Claims{}
		data, err := claims.ValidateJWT(authorization)
		if err != nil {
			base.RespData(c, nil, err)
			c.Abort()

			return
		}
		c.Set("user_id", data.Id)
		c.Next()
	}
}
